package com.fhz.a2002;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;

/**
 * 时间:2022/4/19
 *
 */
public class MyDialog extends Dialog {
    private TextView title;
    private String titleStr;
    private TextView message;
    private String messageStr;
    private Button no;
    private Button yes;

    //new
    public MyDialog(@NonNull Context context) {
        super(context);
    }

    //xml
    public MyDialog(@NonNull Context context, int themeResId) {
        super(context, themeResId);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.mydialog_layout);

        title = (TextView) findViewById(R.id.title);
        message = (TextView) findViewById(R.id.message);
        no = (Button) findViewById(R.id.no);
        yes = (Button) findViewById(R.id.yes);


        yes.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//                Toast.makeText(App.context, "yes", Toast.LENGTH_SHORT).show();
                //写一个接口,让外部调用
                myListener.onClick();
            }
        });

        no.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                myNoListener.onClick();
            }
        });


        if (titleStr !=null){
            title.setText(titleStr);
        }

        if(messageStr != null){
            message.setText(messageStr);
        }
    }


    //1.定义一个内部的接口
    public interface MyListener{
        void onClick();
    }
    //2.声明一个成员
    private MyListener myListener;

    //3.给成员赋值
    public void setMyListener(MyListener myListener) {
        this.myListener = myListener;
    }

    //1.定义一个内部的接口
    public interface MyNoListener{
        void onClick();
    }
    //2.声明一个成员
    private MyNoListener myNoListener;

    //3.给成员赋值

    public void setMyNoListener(MyNoListener myNoListener) {
        this.myNoListener = myNoListener;
    }

    public void setTitle(String title) {
        this.titleStr = title;
    }

    public void setMessageStr(String messageStr) {
        this.messageStr = messageStr;
    }
}

